import geoviews as gv
import geoviews.feature as gf
from config.MainConfig import get_config
from config.params import globalmodel
import pandas as pd
from cartopy import crs
import numpy as np
from os.path import join
import os
import xarray as xr
import datetime
from datetime import timedelta
from proj_io.common_io import load_obj
gv.extension('bokeh')
config = get_config()
Reading and plotting the first day for the region of interest.
output_folder = config[globalmodel.caribbean_from_global_folder]
file_name = join(output_folder,F"2010_1.pkl")
cf = load_obj(file_name)
bbox = (-99, 0, -49, 30)
c_date = '2010-01-01'
lats = cf[c_date]['lat']
lons = cf[c_date]['lon']
print("Done reading data!")
Done reading data!
gv_data = gv.Points(zip(lons,lats)).opts(color="red")
# (gv_data * gf.land.opts(fill_color='grey', scale='50m')).opts('Feature',fixed_bounds=True, height=600, width=800)
(gv.tile_sources.Wikipedia * gv_data.opts(width=800, height=600) )
Loading data for specific month
print("Loading data...")
reduce_by = 1 # If we want to subsample the data being displayed
my_data = {}
c_year = 2010 # Year to start plotting
c_month = 1 # Month to start plotting
tot_months = 1 # Currently must be 1
c_date = datetime.date(c_year, c_month, 1)
data_by_month = {}
last_date = datetime.date(c_year, c_month+tot_months, 1) if c_month+tot_months < 12 else datetime.date(c_year+1, c_month+tot_months-11, 1)
print(F"Reading data from {c_date} to {last_date}")
file_name = join(output_folder,F"{c_year}_{c_month}.pkl")
cf = load_obj(file_name)
while c_date < last_date:
date_str = c_date.strftime("%Y-%m-%d")
lats = cf[date_str]['lat'][::reduce_by]
lons = cf[date_str]['lon'][::reduce_by]
# my_data.update({date_str:gv.Points(zip(lons,lats)) * gf.land.opts(fill_color='grey', scale='50m').opts(color="red")})
my_data.update({date_str:gv.Points(zip(lons,lats)).opts(color="red", width=800, height=600) })
c_date += timedelta(days=1)
print("Done!!!")
Loading data... Reading data from 2010-01-01 to 2010-02-01 Done!!!
Plotting data for specific month, it will take some time to make the plot (if there is a start between the brackets on the left it means it is still loading)
# (gf.land.opts(fill_color='grey', scale='50m') * gv.HoloMap(my_data, kdims='time')).opts('Feature',fixed_bounds=True, height=500, width=700)
(gv.tile_sources.Wikipedia * gv.HoloMap(my_data, kdims='time')).opts('Feature',fixed_bounds=True)